﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace CSReporter
{
    public partial class MonitorForm : Form
    {
        public MonitorForm()
        {
            InitializeComponent();
        }

        private void monitorRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(e.LinkText);
        }

        private void AddLine(string str, Color color)
        {
            // Filter non-printable ASCII characters with the exception of 0x10 (newline).
            str = Regex.Replace(str, "[\u0000-\u0009\u000B-\u001F\u0080-\u00FF]", "");
            // Invoke a delegate to handle writing text to monitorRichTextBox.
            monitorRichTextBox.Invoke(new EventHandler(delegate
            {
                // Unselect any selected text.
                monitorRichTextBox.DeselectAll();
                // Set the font color;
                monitorRichTextBox.SelectionColor = color;
                // Write the string to the RichTextBox.
                monitorRichTextBox.AppendText(str);
                // Scroll down, if needed, so we can see the new text.
                monitorRichTextBox.ScrollToCaret();
            }));
        }
    }
}
